/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.butler.cezary.syncTool.storage.metadata;

import java.io.File;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author Czarek
 */
public class FileMetadata implements Serializable {
    private FileVersionMetadata currentVersion;
    private Set<FileVersionMetadata> versionSet;
    private File file;

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final FileMetadata other = (FileMetadata) obj;
        if (this.currentVersion != other.currentVersion && (this.currentVersion == null || !this.currentVersion.equals(other.currentVersion))) {
            return false;
        }
        if (this.versionSet != other.versionSet && (this.versionSet == null || !this.versionSet.equals(other.versionSet))) {
            return false;
        }
        if (this.file != other.file && (this.file == null || !this.file.equals(other.file))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash + (this.file != null ? this.file.hashCode() : 0);
        return hash;
    }

    public FileMetadata(FileVersionMetadata currentVersion, File file) {
        this.currentVersion = currentVersion;        
        this.file = file;
        versionSet = new HashSet<FileVersionMetadata>();
        versionSet.add(currentVersion);
    }

    public FileVersionMetadata getCurrentVersion() {
        return currentVersion;
    }

    public File getFile() {
        return file;
    }

    public Set<FileVersionMetadata> getVersionSet() {
        return versionSet;
    }
    
    public void updateCurrentVersion(FileVersionMetadata cuFileVersionMetadata){
        versionSet.add(cuFileVersionMetadata);
        //TODO w asercji sprawdzenie poprawności podłączenia poprzedniej wersji może ?
        //to nie musi być dobry pomysł, możemy chcieć zachować dowolność w ustawianiu poprzedniej wersji 
        currentVersion = cuFileVersionMetadata;
    }
}
